package logic

import (
	"context"
	"fmt"
	"good_srv/cache"

	"good_srv/good"
	"good_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDelLogic {
	return &CartDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 购物车删除
func (l *CartDelLogic) CartDel(in *good.CartDelRequest) (*good.CartDelResponse, error) {
	// todo: add your logic here and delete this line
	err := cache.CartDel(in.UserId, in.GoodsId)
	if err != nil {
		logx.Error("购物车删除失败")
		return nil, fmt.Errorf("购物车删除失败")
	}
	return &good.CartDelResponse{}, nil
}
